﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MixScript.Appl.Session;
//using MixScript.DBService;

namespace MixScript.BLL.ApplAdmin
{

    #region Public Type
    public struct sNodeMenu
    {
        private string _nodeid;

        public string Nodeid
        {
            get { return _nodeid; }
            set { _nodeid = value; }
        }
        private string _parentid;

        public string Parentid
        {
            get { return _parentid; }
            set { _parentid = value; }
        }
        private string _procid;

        public string Procid
        {
            get { return _procid; }
            set { _procid = value; }
        }
        private string _modulname;

        public string Modulname
        {
            get { return _modulname; }
            set { _modulname = value; }
        }
        private string _proctype;

        public string Proctype
        {
            get { return _proctype; }
            set { _proctype = value; }
        }
        private string _nodetext;

        public string Nodetext
        {
            get { return _nodetext; }
            set { _nodetext = value; }
        }

        private string _procdesc;

        public string Procdesc
        {
            get { return _procdesc; }
            set { _procdesc = value; }
        }

    } 
    #endregion
    
    public class cMenu :cBaseBLL
    {
       

        public sNodeMenu NdMenu;
        private cApplSession oSession;
        public cMenu()
        {
        }

        public bool getAuthMenu(ref DataTable dt)
        {
            try
            {
                string ssql = "select a.nodeid,a.proctype,b.menuid from sy_nodemenu a ";
                ssql += "left join (select menuid from sy_secmatrix ";
                ssql += "where groupid in (select groupid from sy_mapusergroup where userid='" +oSession.userID  + "'))b ";
                ssql += "on a.nodeid=b.menuid ";

                dt = Dbserver.ExecuteQuery(ssql, "menu");
                if (dt.Rows.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }

               




            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        private bool mappingToStruck(DataTable dt, ref sNodeMenu nm)
        {
            nm.Nodeid = dt.Rows[0]["nodeid"].ToString();
            nm.Parentid = dt.Rows[0]["parentid"].ToString();
            nm.Procid = dt.Rows[0]["procid"].ToString();
            nm.Modulname = dt.Rows[0]["modulname"].ToString();
            nm.Proctype = dt.Rows[0]["proctype"].ToString();
            nm.Nodetext = dt.Rows[0]["nodetext"].ToString();
            nm.Procdesc = dt.Rows[0]["procdesc"].ToString();
            return true;

        }

        #region GetProcessID

        public bool getprocid(string snodeid,ref sNodeMenu nm)
        {
            try
            {
                DataTable dt= new DataTable();
                 nm = new sNodeMenu();
                if (getprocid(snodeid, ref dt))
                {
                    mappingToStruck(dt, ref nm);
                }
                return true;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public bool getprocid(string snodeid)
        {
            DataTable dt= new DataTable();
            if (getprocid(snodeid, ref dt))
            {
                return mappingToStruck(dt, ref NdMenu);
            }
            return false;
        }
		public bool getprocid(string snodeid, ref DataTable dt)
        {
            try
            {
                 dt = new DataTable();
                 string sql = "select * from vsy_nodeproses where nodeid='" + snodeid + "'";

              dt=  Dbserver.ExecuteQuery(sql, "ndmn");
              if (dt.Rows.Count > 0)
              {
                  return true;
              }
              else
              {
                  return false;
              }

            }
            catch (Exception ex)
            {

                throw ex;
            }

        } 
	#endregion
    }

}
